<template>
  <view class="navs-container">
    <view class="navs-wrapper">
      <view
        v-for="(item, index) in displayedItems"
        :key="index"
        class="nav-item"
        @click="goToPage(item)"
      >
        <view class="nav-icon-wrapper">
          <image :src="item.imgUrl" class="nav-icon" mode="aspectFit"></image>
        </view>
        <text class="nav-text">{{ item.title }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    data_list: {
      type: Array,
      default: () => []
    },
    bgColor: {
      type: String,
      default: '#ffffff'
    }
  },
  computed: {
    displayedItems() {
      // 如果数据项少于6个，直接显示所有项
      if (this.data_list.length <= 6) {
        return this.data_list;
      }

      // 如果数据项多于6个，只显示前6个
      return this.data_list.slice(0, 6);
    }
  },
  methods: {
    goToPage(item) {
      if (!item.linkUrl) {
        this.show_msg('该功能暂未开放');
        return;
      }
      this.gotoPath(item.linkUrl, false, null, item.linkType);
    },
    show_msg(message) {
      uni.showToast({
        title: message,
        icon: 'none'
      });
    }
  }
}
</script>

<style lang="scss">
.navs-container {
  width: 100%;
  background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%);
  padding: 30rpx 0 20rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  border-radius: 0 0 30rpx 30rpx;
}

.navs-wrapper {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  padding: 0 20rpx;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 33.33%;
  padding: 20rpx 0;
  margin-bottom: 10rpx;
}

.nav-icon-wrapper {
  width: 100rpx;
  height: 100rpx;
  border-radius: 24rpx;
  background: linear-gradient(135deg, #fff 0%, #ff9900 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15rpx;
  box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;

  &:active {
    transform: scale(0.95);
  }
}

.nav-icon {
  width: 60rpx;
  height: 60rpx;
  display: block;
}

.nav-text {
  font-size: 26rpx;
  color: #333;
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

// 响应式调整
@media screen and (min-width: 768px) {
  .nav-item {
    width: 16.66%;
  }

  .nav-icon-wrapper {
    width: 110rpx;
    height: 110rpx;
  }

  .nav-icon {
    width: 70rpx;
    height: 70rpx;
  }
}
</style>
